package com.xpm.adapter.muliti;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.xpm.R;
import com.xpm.entity.MulitTypeBean;

import java.util.List;

public class MulitiTypeAdapter extends RecyclerView.Adapter {
    //定义三种常量类型
    public static final int TYPE_ONE = 0;
    public static final int TYPE_TWO = 1;
    public static final int TYPE_THREE =  2;



    private final List<MulitTypeBean> mDatas;

    public MulitiTypeAdapter(List<MulitTypeBean> datas) {
        this.mDatas = datas;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = null;
        // 创建界面
        if(viewType == TYPE_ONE){
            view = View.inflate(parent.getContext(), R.layout.muliti_item_one, null);
            return new OneViewHolder(view);
            // 创建第一个界面
        }
        if(viewType == TYPE_TWO){
            view = View.inflate(parent.getContext(), R.layout.muliti_item_two, null);
            return new TwoViewHolder(view);
            // 创建第二个界面
        }
        // 创建第三个界面
        view = View.inflate(parent.getContext(), R.layout.muliti_item_three, null);
        return new ThreeViewHolder(view);

    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return mDatas == null? 0 : mDatas.size();
    }

    /**
     * 返回条目类型，根据条目类型返回条目类型
     * @param position position to query
     * @return
     */
    @Override
    public int getItemViewType(int position) {
        if(mDatas.get(position).type == 0){
            return TYPE_ONE;
        }
        if(mDatas.get(position).type == 1){
            return TYPE_TWO;
        }
        return TYPE_THREE;
    }



    public class OneViewHolder extends RecyclerView.ViewHolder{
        public OneViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
    public class TwoViewHolder extends RecyclerView.ViewHolder{
        public TwoViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
    public class ThreeViewHolder extends RecyclerView.ViewHolder{
        public ThreeViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }


}
